"""
服务端
"""
from gevent import spawn, monkey

monkey.patch_all()
from socket import *

s = socket()
s.bind(('127.0.0.1', 8000))
s.listen()


def msg_loop(conn):
    while True:
        msg = conn.recv(1024).decode('utf8')
        if not msg: break
        print(f'client:{msg}')
        conn.send(msg.upper().encode('utf8'))
    conn.close()


if __name__ == '__main__':

    while True:
        conn, addr = s.accept()
        print(conn, addr)
        spawn(msg_loop, conn)
